//
//  CZTopSegMentItemModel.m
//  ForChangZhou
//
//  Created by 布丁 on 2020/12/1.
//  Copyright © 2020 KMasker. All rights reserved.
//

#import "CZTopSegMentItemModel.h"

@implementation CZTopSegMentItemModel


- (CGFloat)itemWidth {
//    if (!_itemWidth) {
//        if (self.itemName.length <  1) {
//            return 0;
//        }else {
//            if (_textFont == nil) {
//                _textFont = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
//            }
//            _itemWidth = [self boundsSizeFor:CGSizeMake(1000, [_textFont pointSize]) withFont:_textFont text:self.itemName].width;
//            if (_itemWidth != 0) {
//                _itemWidth = _itemWidth+15;
//            }
//        }
//    }
    if (self.itemName.length <  1) {
        return 0;
    }else {
        if (_textFont == nil) {
            _textFont = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        }
        _itemWidth = [self boundsSizeFor:CGSizeMake(1000, [_textFont pointSize]) withFont:_textFont text:self.itemName].width;
        if (_itemWidth != 0) {
            _itemWidth = _itemWidth+15;
        }
    }
    return _itemWidth;
}

- (CGSize)boundsSizeFor:(CGSize)maxSize withFont:(UIFont *)font text:(NSString *)text{
    CGRect rect = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
    return rect.size;
}
@end
